<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class ConfigDataEditTwo extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {

        $updates = [
            [
                'conditions' => ['code' => 'IS_ENABLED'],
                'column_to_update' => [
                    ['name' => '开启OSS'],
                    ['tip' => '开启OSS']
                ]
            ],
            [
                'conditions' => ['code' => 'BIND_DOMAIN'],
                'column_to_update' => [
                    ['name' => '绑定域名'],
                    ['tip' => '绑定域名']
                ]],
            [
                'conditions' => ['code' => 'PRODUCT_DOMAIN'],
                'column_to_update' => [
                    ['name' => '生产域名'],
                    ['tip' => '生产域名']
                ]]
        ];

        $table = $this->table('ctmon_config');
        foreach ($updates as $update) {
            $builder = $this->getUpdateBuilder();
            $builder->update($table->getName())
                ->set($update['column_to_update'])
                ->where($update['conditions'])
                ->execute();
        }
    }
}
